/* eslint-disable @typescript-eslint/triple-slash-reference */
/* eslint-disable @typescript-eslint/ban-ts-comment */
/// <reference path='../node_modules/@i3yun/viewer/dist/dts/Sippreep.d.ts'/>

/**
 * 修改单个模型的节点关闭，增加记录
 */
export class VisibilityManager extends Sippreep.Viewing.Private.VisibilityManager {
    readonly version = "2023.02.23";
    private model;
    /**
     * 关闭的dbids
     */
    private nodeOffList: number[] = [];

    constructor(viewerImpl: Sippreep.Viewing.Private.Viewer3DImpl, model: Sippreep.Viewing.Model) {
        // @ts-ignore
        super(viewerImpl, model);
        this.model = model;
    }
    setNodeOff(node: number | number[], isOff: boolean, nodeChildren?: number[], nodeFragments?: number[]): void {
        const _node: number[] = typeof (node) == "number" ? [node] : node;
        this._recordNodeOff(_node, isOff);
        for (const dbid of _node) {
            // 原方法不支持传入数组
            super.setNodeOff(dbid, isOff, nodeChildren, nodeFragments);
        }
    }
    private _recordNodeOff(node: number[], isOff: boolean) {
        const newNodes = node.slice();
        if (isOff) {
            // 求合集
            this.nodeOffList = Array.from(new Set(newNodes.concat(this.nodeOffList)));
        } else {
            // 求差集
            this.nodeOffList = this.nodeOffList.filter(x => !newNodes.includes(x));
        }
    }

    getOffNodes(): number[] {
        return this.nodeOffList;
    }

    /**
     * 将记录的关闭的模型部件全部打开
     */
    resetNodeOff() {
        this.setNodeOff(this.nodeOffList, false);
        this.nodeOffList = [];
    }

}
